package java_test.nettest;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

public class TCPTest1 {
    public static void main(String[] args) {
        cloent();
    }

    public static void cloent() {
        InetAddress inetAddress;
        Socket socker = null;
        OutputStream outputStream = null;
        try {
            inetAddress = InetAddress.getByName("127.0.0.1");
            socker = new Socket(inetAddress, 8899);
            outputStream = socker.getOutputStream();
            outputStream.write("我是客户端1\n".getBytes());
            outputStream.write("我是客户端2\n".getBytes());
            outputStream.write("我是客户端3".getBytes());
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (socker != null) {
                try {
                    socker.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
